package com.gxa.service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.base.RespResult;
import com.gxa.service.dto.SpecificationAreaDto;
import com.gxa.service.entity.Specification;
import com.gxa.service.entity.SpecificationArea;


import com.gxa.service.mapper.SpecificationAreaMapper;
import com.gxa.service.mapper.SpecificationMapper;
import com.gxa.service.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class SpecificationServiceImpl extends ServiceImpl<SpecificationMapper, Specification>
    implements SpecificationService {

    @Autowired
    private SpecificationMapper specificationMapper;
    @Autowired
    private SpecificationAreaMapper specificationAreaMapper;
    @Override
    public RespResult findSpecificationById(Integer id) {
        List<Specification> specifications=specificationMapper.findSpecificationById(id);
        List<SpecificationAreaDto> specificationAreaDtos=new ArrayList<>();
        for(int i=0;i<specifications.size();i++){
            Integer specificationId= specifications.get(i).getId();
            List<SpecificationArea> specificationAreaList=specificationAreaMapper.findById(specificationId);
            SpecificationAreaDto specificationAreaDto=new SpecificationAreaDto();
            specificationAreaDto.setAreas(specificationAreaList);
            specificationAreaDto.setSpecificationName(specifications.get(i).getSpecificationName());
            specificationAreaDto.setSpecificationId(specificationId);
            specificationAreaDtos.add(specificationAreaDto);
        }
        return RespResult.success(specificationAreaDtos);
    }
}




